home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 25
/
Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso
/
Aminet
/
comm
/
net
/
AMarquee1_48.lha
/
AMarquee
/
examples
/
BounceCount.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-04-10
|
3KB
|
105 lines
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos/dos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/AMarquee_protos.h>
#include <pragmas/AMarquee_pragmas.h>
struct Library * AMarqueeBase = NULL;
struct QSession * session = NULL;
void CleanExit(void)
{
if (session) QFreeSession(session); /* This MUST be done before we close the library! */
if (AMarqueeBase) CloseLibrary(AMarqueeBase);
printf("All done.\n");
}
/* Main program--simply increments our counter whenever someone else increments theirs */
int main(int argc, char ** argv)
{
char * connectTo, * progName;
int port = 2957;
int count = 0;
char temp[700];
BOOL BDie = FALSE;
atexit(CleanExit);
printf("Usage Note: BounceCount [hostname=localhost] [myname=bounce]\n");
connectTo = (argc > 1) ? argv[1] : "localhost";
progName = (argc > 2) ? argv[2] : "bounce";
if ((AMarqueeBase = OpenLibrary("amarquee.library",37L)) == NULL)
{
printf("Couldn't open amarquee.library v37!\n");
exit(RETURN_ERROR);
}
printf("Connecting to %s:%i...\n",connectTo, port);
if ((session = QNewSession(connectTo, port, progName)) == NULL)
{
printf("Couldn't connect to server %s:%i\n",connectTo, port);
CloseLibrary(AMarqueeBase);
exit(RETURN_WARN);
}
printf("BounceCount connected to server %s:%i\n",connectTo, port);
/* Setup */
sprintf(temp,"/#?/~(%s)/count",progName);
(void)QSetOp(session, "count", "0", 2);
(void)QSubscribeOp(session, temp, -1);
(void)QGetOp(session, temp, -1L);
(void)QGo(session,0L);
while(BDie == FALSE)
{
struct QMessage * qMsg;
ULONG signals = (1L << session->qMsgPort->mp_SigBit) | (SIGBREAKF_CTRL_C);
/* Wait for next message from the server */
signals = Wait(signals);
if (signals & (1L << session->qMsgPort->mp_SigBit))
{
while(qMsg = (struct QMessage *) GetMsg(session->qMsgPort))
{
if (qMsg->qm_Status != QERROR_NO_ERROR)
{
printf("Error %i detected!\n", qMsg->qm_Status);
BDie = TRUE;
}
else
{
if ((qMsg->qm_Path)&&(qMsg->qm_Data))
{
/* Must be in response to our subscription! */
int val = atoi(qMsg->qm_Data);
/* Raise the stakes a bit :) */
printf("I see a %i... ",val);
if (val >= count)
{
printf("and I raise it to %i!\n",val+1);
sprintf(temp,"%i",val+1);
(void) QSetOp(session, "count", temp, strlen(temp)+1);
(void) QGo(session,0L);
count = val+1;
}
else printf("but my count of %i is higher.\n",count);
}
}
FreeQMessage(session,qMsg);
}
}
if (signals & SIGBREAKF_CTRL_C) BDie = TRUE; /* Quit if CTRL-C pressed */
}
}